package com.match.plugin.disruptor.handler;

import com.hazelcast.core.HazelcastInstance;
import com.lmax.disruptor.WorkHandler;
import com.match.common.model.dto.MatchOrder;
import com.match.match.LimitOrderMatchService;
import com.match.match.MarketOrderMatchService;
import com.match.match.MatchDetailHandler;
import com.match.plugin.hazelcast.HazelcastPlugin;

/**
 * @ClassName: MatchHandler
 */
public class MatchHandler implements WorkHandler<MatchOrder>{
	
	MarketOrderMatchService marketservice = MarketOrderMatchService.getMarketOrderMatchService();
	LimitOrderMatchService limitservice = LimitOrderMatchService.getLimitOrderMatchService();
	MatchDetailHandler matchDetailHandler = MatchDetailHandler.getMatchDetailHandler();
	HazelcastInstance hzInstance = HazelcastPlugin.hazelcastInstance;
	
	@Override
	public void onEvent(MatchOrder order) throws Exception {
		// 撮合处理器，线性消费
		if(order.getIsMarket()) {
			marketservice.doMatch(order,hzInstance,matchDetailHandler);
		}else {
			limitservice.doMatch(order,hzInstance,matchDetailHandler);
		}
	}
}
